﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web;
using WLMCoreLibrary;
using SAW_Core;

namespace SAW
{
    public partial class ImpresionReporte : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["tablaReporte"] != null)
            {

                string tableHeader = "";
                string titulo = " [" + Request["fechaInicial"] + " - " + Request["fechaFinal"] + "]";
                switch (Request["tipo"])
                {
                    case "CxC":
                        titulo="Reporte de Cuentas por Cobrar "+titulo;
                        tableHeader = "<tr><th>No. Cot.</th><th>No. Fac.</th><th style='display:none'></th><th style='display:none'></th><th style='display:none'></th><th>Fecha.</th><th style='display:none'></th><th style='display:none'></th><th style='display:none'></th><th>Status</th><th>Razon social</th><th style='display:none'></th><th>Total</th><th>Pagado</th><th>Pendiente</th><th>dias Credito</th><th>Dias Vencido</th>";
                        break;
                    case "CxP":
                        titulo="Reporte de Cuentas por Pagar "+titulo;
                        tableHeader = "<tr><th>No. Cot.</th></th><th>No. Ped.</th><th style='display:none'></th><th>No. Sal.</th><th>F. Cot.</th><th>F. Ped.</th><th style='display:none'></th><th>F. Sal.</th><th>Razon social</th><th style='display:none'></th><th>Total</th><th>Pagado</th><th>Pendiente</th><th>Cre.</th><th>Ven.</th></tr>";
                        break;
                    case "Ventas":
                        titulo = "Reporte de Ventas " + titulo;
                        tableHeader = "<tr><th>No. Cot.</th></th><th>No. Ped.</th><th style='display:none'></th><th>No. Sal.</th><th>F. Cot.</th><th>F. Ped.</th><th style='display:none'></th><th>F. Sal.</th><th>Razon social</th><th style='display:none'></th><th>Total</th><th>Pagado</th><th>Pendiente</th><th>Cre.</th><th>Ven.</th></tr>";
                        break;
                    case "VentasProducto":
                        titulo = "Reporte de Ventas Por Producto " + titulo;
                        tableHeader = "<tr><th style='display:none'></th><th>No. Prod.</th></th><th>Clave</th><th>Descripcion</th><th>Categoria</th><th>Linea</th><th>Marca</th><th>Stock</th><th>Vendidos</th><th >Precio Promedio</th><th>Costo</th><th>Total Vendidos</th><th>Ingresos Estimados</th></tr>";
                        break;
                    case "Compras":
                        titulo = "Reporte de Compras " + titulo;
                        tableHeader = "<tr><th>No. Cot.</th></th><th>No. Ped.</th><th style='display:none'></th><th>No. Sal.</th><th>F. Cot.</th><th>F. Ped.</th><th style='display:none'></th><th>F. Ent.</th><th>Razon social</th><th style='display:none'></th><th>Total</th><th>Pagado</th><th>Pendiente</th><th>Cre.</th><th>Ven.</th></tr>";
                        break;
                    case "Stock":
                        titulo = "Reporte de Stocks " + titulo;
                        tableHeader = "<tr><th>No. Cot.</th></th><th>No. Ped.</th><th style='display:none'></th><th>No. Sal.</th><th>F. Cot.</th><th>F. Ped.</th><th style='display:none'></th><th>F. Sal.</th><th>Razon social</th><th style='display:none'></th><th>Total</th><th>Pagado</th><th>Pendiente</th><th>Cre.</th><th>Ven.</th></tr>";
                        break;
                    case "Banco":
                        titulo = "Reporte de Movimientos Bancarios " + titulo;
                        tableHeader = "<tr><th>ID</th></th><th>Aplicado</th><th>Cuenta</th><th>No.Cheq.</th><th>N. Ped.</th><th>Descripcion</th><th>Abono</th><th>Retiro</th><th>SaldoInicial</th><th >Saldo Final</th></tr>";
                        break;
                }


                string style = "<style>td,th{vertical-align:top;border-bottom:solid 1px #ccc; margin:0px; padding:0px;}</style>";
                string html = "<html><body style='font-family:arial;'>" + style +"<h2>"+ titulo + "</h2><table style='font-size:12px; width:1025px;font-family:arial;' cellpadding='0' cellspacing='0'>" + tableHeader + Request["tablaReporte"] + "</table><h4>Generado:  "+DateTime.Now.ToLongDateString()+" a las "+DateTime.Now.ToLongTimeString()+"</h4></body></html>";
                PDFCreator pdf = new PDFCreator();
                pdf.CrearPDFdeHTML(html, titulo.Replace("/","-")+DateTime.Now.ToString("yyyyMMddhhmm"), "Reportes/", true, true);
            }
        }
    }
}